var orderComment = -1;
jQuery(function(){
	if(userid == null || userid == ''){
		alertLogin();
		return;
	}
	initData("","")
	$("#cancel").click(function(){
		$('.attention_box').addClass('disno1');
		$("#bad").removeClass("bad_sel")
		$("#good").removeClass("good_sel")
		$("#comment").val("");
	});
	$("#sure").click(function(){
		sure();
	});
	$("#good").click(function(){
		if($(this).hasClass("good_sel")){
			orderComment = -1
			$(this).removeClass("good_sel")
			$("#bad").removeClass("bad_sel");
		}else{
			orderComment = 1;
			$(this).addClass("good_sel")
			$("#bad").removeClass("bad_sel")

		}
	});
	$("#bad").click(function(){
		if($(this).hasClass("bad_sel")){
			orderComment = -1
			$("#good").removeClass("good_sel")
			$(this).removeClass("bad_sel")
		}else{
			$(this).addClass("bad_sel");
			$("#good").removeClass("good_sel")
			orderComment = 0
		}
	});
	$("#payCancel").click(function(){
		$("#payNow").addClass("disno1");
		$("#payNow").find("img").attr("src","")
		$("#remark").val("")
	})

	$("#payConfirm").click(function(){
		payMoney();
	});

	doubleClick("img1",function(obj){
		$(obj).attr("src", "");
		$(obj).parent().addClass("disno1");
		$("#filePicker").show()
	})
	doubleClick("img2",function(obj){
		$(obj).attr("src", "");
		$(obj).parent().addClass("disno1");
		$("#filePicker").show()
	})
});
function initData(orderStatus,shipStatus){
	$(".order_show").html("");
	jQuery.ajax({
		url:server_url+"/rest/buyerOrder/getOrders.do",
		data:{userId:userid,orderStatus:orderStatus,shipStatus:shipStatus},
		success:function(data){
			if(data.data.length>0){
				mapIfExist(function(order){
					console.log(order)
					var order_status = order.orderStatus;
					var html = '<div class="gray"></div>\
						<div class="pos_det" onclick="javascript:toOrderDetail('+order.id+');">\
					<p class="order_num">订单号：'+ order.orderCode+' <span>'+ order.orderStatusName+'</span></p>\
					<div class="det_con">\
					<img src="'+ order.lstOrderDetail[0].productPic+'" alt="" class="">\
					<div class="">\
					<div class="con_tit">\
					<p>'+ order.lstOrderDetail[0].productName+'</p>\
					<span>¥'+ order.lstOrderDetail[0].productPrice+'/头</span>\
					</div>\
					<p class="con_normal">类别：'+ order.lstOrderDetail[0].spec+' <span><i>X</i>'+ order.lstOrderDetail[0].productNum+'</span></p>\
					<p class="con_normal">货源地：'+ order.lstOrderDetail[0].areaName+'</p>\
					</div>\
					<div class="ps_det">合计：¥'+ order.price+'</div>\
					</div>\
					</div>';
					html += '<div class="total_box">\
					<span><a href="tel:4008637797" style="color:#999999">联系客服</a> </span>';
					if(order_status == '01'){
						html += '<div onclick="javascript:cancel('+order.id+','+order.lstOrderDetail[0].supplyProductID+','+order.lstOrderDetail[0].productNum+')">取消订单</div>\
							</div>';
					}
					if(order_status == '03'){
						html += '<div onclick="javascript:payNow('+order.id+')">确认付款</div>\
							</div>';
					}
					if(order_status == '05'){
						html += '<div onclick="javascript:confirmOrder('+order.id+')">确认收货</div>\
							</div>';
					}
					if(order_status == '06'){
						html += '<div onclick="javascript:evaluateOrder('+order.id+');">立即评价</div>\
							</div>';
					}
					$(".order_show").append($(html))
				}, data.data);
			}else{
				if(orderStatus == "" && shipStatus == ""){
					jQuery("<div>"+
							"<p style='font-size:0.35rem; padding:50% 5% 50% 5%; text-align:center;'>您暂时还没有交易订单，快去采购吧！</p>"+
							"</div>").appendTo($(".order_show"));
				}
			}
		}
	});
}


